
#ifndef HELP_MACROS_H
#define HELP_MACROS_H

#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
#include <sstream>

#define DECLARE_SINGLETON(CLASS, LOCK) friend class CSingletonT<CLASS, LOCK>; private: CLASS() {} virtual ~CLASS() {}
#define DECLARE_SVC_OBJ(CMDID) virtual uint32_t getCmdId() const { return CMDID; }
#define DECLARE_CATEGORY(CATEID) virtual uint32_t getCateId() const { return CATEID; }
#define DECLARE_CMDID_RANGE(BEGINID, ENDID) virtual void getCmdIdRange(uint32_t& ulCmdIdBegin, uint32_t& ulCmdIdEnd) const { ulCmdIdBegin = BEGINID; ulCmdIdEnd = ENDID; }
#define DECLARE_CMDID(CMDID) DECLARE_CMDID_RANGE(CMDID, CMDID)
#define DECLARE_STATEFUL() public: virtual bool isStateful() const { return true; } 
#define DECLARE_STATELESS() public: virtual bool isStateful() const { return false; } 
#define TYPE_TRANSFER(VAL_HANDLE, P_VAL_HANDLE, P_SVC_OBJ) VAL_HANDLE* P_VAL_HANDLE = dynamic_cast<VAL_HANDLE*>(P_SVC_OBJ);}
#define PROTO_VERSION() getSvcCntl()->getDBPkgInfoBeforeParse().stHead.wVersion

#define R_FINISHED  { return 0; }
#define R_CONTINUE  { return 1; }
#define R_EXCEPTION { return -1; }

#define EXPORT(X)   
#define TIMER(X)   
#define PARAM_DEF_H_BEGIN
#define PARAM_DEF_H_END
#define SERVICE
#define TIMER_HANDLER
#define AUTH_CHECK(LEVEL, ACTION) \
do { \
std::string sErrMsg; \
uint32_t dwErrCode = ONLINE_SEESION_R->IsUserOnlineValid(rCntlInfo, COnlineSessionCheck::LEVEL, COnlineSessionCheck::ACTION, sErrMsg); \
if(dwErrCode != 0) \
{ \
	return ERR_APP_UIN_NOT_AUTH; \
} \
} while (0)

#ifndef _UNITTEST
#define DEBUG_TRACE(X) \
    do { \
	std::stringstream __oss__; \
	__oss__.str(""); \
    __oss__ << __FILE__ << ", " << __LINE__ << ", " << __func__ << " | " << X; \
    getSvcCntl().LogDebug(__oss__.str()); \
    } while (0)

#define INFO_TRACE(X) \
    do { \
	std::stringstream __oss__; \
	__oss__.str(""); \
    __oss__ << __FILE__ << ", " << __LINE__ << ", " << __func__ << " pid[" << getpid() << "] | " << X; \
    getSvcCntl().LogInfo(__oss__.str()); \
    } while (0)

#define ERROR_TRACE(X) \
    do { \
	std::stringstream __oss__; \
	__oss__.str(""); \
    __oss__ << __FILE__ << ", " << __LINE__ << ", " << __func__ << " pid[" << getpid() << "] | " << X; \
    getSvcCntl().LogError(__oss__.str()); \
    } while (0)

#define SVC_TRACE(X) \
    do { \
	std::stringstream __oss__; \
	__oss__.str(""); \
    __oss__ << __FILE__ << ", " << __LINE__ << ", " << __func__ << " pid[" << getpid() << "] | " << X; \
    getSvcCntl().LogHex(__oss__.str()); \
    } while (0)
#else
#define DEBUG_TRACE(X) \
    do { \
	std::stringstream __oss__; \
	__oss__.str(""); \
    __oss__ << "[TEST] " << X; \
	std::cout << __oss__.str() << std::endl; \
    } while (0)

#define INFO_TRACE(X) DEBUG_TRACE(X)
#define ERROR_TRACE(X) DEBUG_TRACE(X)
#define SVC_TRACE(X) DEBUG_TRACE(X)

#endif

#define HEADER_SELF_DEFINE_START
#define HEADER_SELF_DEFINE_END
#define SECTION_SELF_DEFINE_START
#define SECTION_SELF_DEFINE_END
#define CPP_SELF_DEFINE_START
#define CPP_SELF_DEFINE_END

const uint32_t BASE_SECONDS = 1160370232;

enum DeployMethod
{
	DEPLOY_MOCK = 0,
	DEPLOY_STANDALONE,
	DEPLOY_DETACH,
};

#endif /* HELP_MACROS_H */


